$(function() {
	var e = 0,
		i = "other/www.543.cn",
		n = "other/www.543.cn",
		o = $(".top_bg #wg_nav"),
		c = $(".top_bg .wg_game"),
		a = $(".sug-auto-complete"),
		r = $(".sug-auto-complete .ui-img-text"),
		l = $("#smart_input"),
		d = "/e/ffcode/presearch.php",
		u = "/e/search/index.php?keyboard=",
		s = function() {
			a.hide()
		},
		p = function() {
			a.show()
		},
		f = f || {};
	f = {
		Util: {
			_Replace: function(e) {
				return e.replace(/^\s+/, "").replace(/\s+$/, "")
			},
			Location: function(e) {
				var t = n + u + encodeURIComponent(f.Util._Replace(e));
				if (location.href.indexOf("/e/search") == -1) window.open(t + "&ch=txt.home.t");
				else window.location = t + "&ch=txt.result.t"
			},
			Search: function() {
				l.focus(function() {
					p(), a.find("dl").show(), a.find(".s-result").hide()
				}).keyup(function() {
					if (f.Util._Replace(l.val()) != "") {
						$(".sug-auto-list span.mywords").html(l.val());
						a.find("dl").hide(), a.find(".s-result").show();
						$.ajax({
							type: "GET",
							url: n + d + "?sk=" + encodeURIComponent(f.Util._Replace(l.val())) + "&_=" + Math.random(),
							dataType: "json",
							timeout: 1e3,
							success: function(e) {
								var i = [];
								goto = function(e) {
									if (f.Util._Replace(e) != "") f.Util.Location(e)
								}, $.each(e, function(e, n) {
									t = n["titlepic"].replace("other/www.543.cn", "");
									i.push('<li class="sugdd_pic" onclick=goto("' + n.title + '")><span class="pic"><img alt="' + n["title"] + '" src="other/www.543.cn' + t + '" width=60 height=63></span><h3><span class="s-name" >' + n["title"] + "</span></h3></li>")
								}), r.empty().append(i.join(""));
								return
							}
						});
						r.empty().append("<li>暂时没有您搜索的数据</li>")
					} else a.find("dl").show(), a.find(".s-result").hide()
				}).blur(s), a.mouseover(function() {
					l.unbind("blur"), p()
				}), a.mouseout(function() {
					l.blur(s), p()
				})
			}
		},
		Variable: {
			remove: function(e) {
				var t = $(".func-area .ui-slide-trigger2 li");
				t.removeClass("current").eq(e).addClass("current")
			},
			s_hide: function(e) {
				var t = $(".top_bg .wg_game");
				t.find(".wg_list li").hide().eq(e).fadeIn()
			},
			inner: function(e) {
				f.Variable.remove(e), f.Variable.s_hide(e)
			}
		},
		Slide: {
			left: function() {
				$(".ui-slide-btn-left").click(function() {
					e--;
					if (e < 0) e = 2;
					f.Variable.inner(e)
				})
			},
			center: function() {
				$(".func-area .ui-slide-trigger2 li").each(function(t) {
					$(this).click(function() {
						f.Variable.inner(t);
						e = t
					})
				})
			},
			right: function() {
				var t = $(".func-area .ui-slide-trigger2 li");
				$(".ui-slide-btn-right").click(function() {
					e++;
					if (e > 2) e = 0;
					f.Variable.inner(e)
				})
			},
			inner: function() {
				f.Slide.left(), f.Slide.center(), f.Slide.right()
			}
		}
	}, desktop = function(e, t) {
		window.location.href = "other/www.543.cn/down.php?t=" + t + "&url=" + e
	}, AddFavorite = function(e, t) {
		if (document.all) {
			try {
				window.external.addFavorite(e, t)
			} catch (i) {
				try {
					window.external.addToFavoritesBar(e, t)
				} catch (n) {
					alert("请使用Ctrl+D添加收藏")
				}
			}
		} else if (window.sidebar && window.sidebar.addPanel) {
			window.sidebar.addPanel(t, e, "")
		} else {
			alert("请使用Ctrl+D添加收藏")
		}
	};
	o.mouseover(function() {
		c.show()
	}).mouseout(function() {
		c.hide()
	});
	f.Util.Search();
	f.Slide.inner();
	$(".top_bg #r_desk").click(function() {
		desktop("", "")
	});
	$(".top_bg #addfavid,.gamefv a#favindex").click(function() {
		AddFavorite("other/www.543.cn/?so=f", "543小游戏")
	})
});
var get_items = function(o,label,data,lens,rows,isno,type){
	var str,a_array = new Array(),
	html = function(data){
		if(typeof(type) != 'undefined'){
			if(type == 1)
				return '<a href="'+data['link']+'" target="_blank"><img src="'+data['image']+'" height="61" width="60" alt="'+data['title']+'">'+data['title']+'</a>';
		}
		return '<a href="'+data['link']+'" target="_blank"><img src="'+data['image']+'" height="78" width="77" alt="'+data['title']+'">'+data['title']+'</a>';
	}
	a_array = data;
	if(isno)
		lens = lens / rows;
	var strs = '';
	for(var j = 0; j<rows; j++){
		str = '';
		for(var i = 0; i<lens; i++){
			len = a_array.length;
			if(len > 0){
				var index = Math.floor(Math.random() * len);
				str += html(a_array[index]);
				a_array.splice(index, 1);
			}else{
				break;
			}
		}
		strs += label.replace('~str',str);
	}
	$(o).append(strs);
}